<html>
<head>
  <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0" />

  <script src="http://localhost:35729/livereload.js"></script>
</head>
<body>
  <a class="download" href="#" name="call_to_action">/call_to_action.html</a><br>
  <a class="download" href="#" name="contacts">/contacts.html</a><br>
  <a class="download" href="#" name="content">/contents.html</a><br>
  <a class="download" href="#" name="features">/features.html</a><br>
  <a class="download" href="#" name="footers">/footers.html</a><br>
  <a class="download" href="#" name="forms">/forms.html</a><br>
  <a class="download" href="#" name="headers">/headers.html</a><br>
  <a class="download" href="#" name="pricings">/pricings.html</a><br>
  <a class="download" href="#" name="teams">/teams.html</a><br>
  <a class="download" href="#" name="testimonials">/testimonials.html</a>
  <iframe style="width: 100%; height: 100%; border: 0;"></iframe>

  <script>
    var nodes = document.body.querySelectorAll('a.download');
    var iframe = document.body.querySelector('iframe');
    var c_name = 'noname';

    var down = function (node, i) {
      iframe.contentWindow.domtoimage.toJpeg(node)
      .then(function (url) {
        var link = document.createElement('a');
        link.download = (i + 1) + '.jpg';
        link.href = url;
        link.click();
      })
    }

    var iframeLoad = function () {
      iframe.removeEventListener(iframe, iframeLoad);

      var iframeDocument = iframe.contentDocument || iframe.contentWindow.document;

      var script = iframeDocument.createElement('script');
      iframeDocument.body.appendChild(script);

      script.onload = function() {
        var nodes = iframeDocument.querySelectorAll('section, header, footer');

        for (var i = 8; i < 9; i++) {
          var node = nodes[i];

          down(node, i);
        }
      }

      script.src = 'dom-to-image/dist/dom-to-image.min.js';
    }

    for (var i = 0; i < nodes.length; i++) {
      var node = nodes[i];
      node.addEventListener('click', function (e) {
        e.preventDefault();

        iframe.src = this.textContent;
        c_name = this.getAttribute('name');

        iframe.addEventListener('load', iframeLoad);
      })
    }
  </script>
</body>
</html>